package leecode

func deleteMiddle(head *ListNode) *ListNode {
	arr := make([]int, 0)
	dummyHead := &ListNode{}
	dummyHead.Next = head

	cur := dummyHead.Next
	for cur != nil {
		arr = append(arr, cur.Val)
		cur = cur.Next
	}
	if len(arr) == 1 {
		return nil
	}
	minIndex := len(arr) / 2
	result := &ListNode{Val: arr[0]}
	temp := result
	for i := 1; i < len(arr); i++ {
		if i == minIndex {
			continue
		}
		result.Next = &ListNode{Val: arr[i]}
		result = result.Next
	}
	return temp
}
